package com.ruoyi.purchase.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.purchase.domain.PurchaseStoreDetail;
import com.ruoyi.purchase.service.IPurchaseStoreDetailService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 入库详情Controller
 *
 * @author wonderland
 * @date 2023-07-17
 */
@RestController
@RequestMapping("/storeDetail")
public class PurchaseStoreDetailController extends BaseController {
    @Autowired
    private IPurchaseStoreDetailService purchaseStoreDetailService;

    /**
     * 查询入库详情列表
     */
    @RequiresPermissions("purchase:detail:list")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseStoreDetail purchaseStoreDetail) {
        startPage();
        List<PurchaseStoreDetail> list = purchaseStoreDetailService.selectPurchaseStoreDetailList(purchaseStoreDetail);
        return getDataTable(list);
    }

    /**
     * 导出入库详情列表
     */
    @RequiresPermissions("purchase:detail:export")
    @Log(title = "入库详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseStoreDetail purchaseStoreDetail) {
        List<PurchaseStoreDetail> list = purchaseStoreDetailService.selectPurchaseStoreDetailList(purchaseStoreDetail);
        ExcelUtil<PurchaseStoreDetail> util = new ExcelUtil<PurchaseStoreDetail>(PurchaseStoreDetail.class);
        util.exportExcel(response, list, "入库详情数据");
    }

    /**
     * 获取入库详情详细信息
     */
    @RequiresPermissions("purchase:detail:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(purchaseStoreDetailService.selectPurchaseStoreDetailById(id));
    }

    /**
     * 新增入库详情
     */
    @RequiresPermissions("purchase:detail:add")
    @Log(title = "入库详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseStoreDetail purchaseStoreDetail) {
        return toAjax(purchaseStoreDetailService.insertPurchaseStoreDetail(purchaseStoreDetail));
    }

    /**
     * 修改入库详情
     */
    @RequiresPermissions("purchase:detail:edit")
    @Log(title = "入库详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseStoreDetail purchaseStoreDetail) {
        return toAjax(purchaseStoreDetailService.updatePurchaseStoreDetail(purchaseStoreDetail));
    }

    /**
     * 删除入库详情
     */
    @RequiresPermissions("purchase:detail:remove")
    @Log(title = "入库详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(purchaseStoreDetailService.deletePurchaseStoreDetailByIds(ids));
    }
}
